package com.xbongbong.saas.model;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.IModel;
import com.xbongbong.saas.domain.entity.ClueUserEntity;
import com.xbongbong.saas.domain.entity.UserTeamEntity;
import org.elasticsearch.action.support.WriteRequest;

import java.util.List;
import java.util.Map;

public interface ClueUserModel extends IModel<ClueUserEntity> {
    /**
     * 保存实体
     *
     * @param clueUserEntity 协同人团队实体
     * @return java.lang.Integer
     * @throws XbbException 数据库异常
     */
    Integer save(ClueUserEntity clueUserEntity) throws XbbException;

    /**
     * 获取单个实体
     *
     * @param key    id主键
     * @param corpid 公司id
     * @return com.xbongbong.saas.domain.entity.ClueUserEntity
     */
    ClueUserEntity getByKey(Long key, String corpid);

    /**
     * 批量插入
     * @param clueUserEntities
     */
    void insertBatch(List<ClueUserEntity> clueUserEntities) throws XbbException;

    void insertBatch(List<ClueUserEntity> clueUserEntities, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    /**
     * 查询协同团队基础列表
     * @param map 参数
     * @return 团队
     */
    List<UserTeamEntity> findBaseEntitys(Map<String, Object> map);

    void batchUpdateByUserIdIn(String corpid, List<Long> idIn, List<UserTeamEntity> teamEntityList, Integer isMain, Integer del) throws XbbException;

    void batchUpdateByUserIdIn(String corpid, List<Long> idIn, List<UserTeamEntity> teamEntityList, Integer isMain, Integer del, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    /**
     * 批量删除
     * @param idIn 线索id
     * @param corpid 公司id
     * @return
     */
    Integer deleteBatchByClueIdIn(List<Long> idIn, String corpid) throws XbbException;

    /**
     * 批量更新
     * @param list
     * @param corpid
     * @return
     * @throws XbbException
     */
    Integer updateBatch(List<ClueUserEntity> list, String corpid) throws XbbException;

    /**
     * 退回公海池解散团队
     * @param corpid
     * @param clueIdList
     */
    void disbandedTeam(String corpid, List<Long> clueIdList, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    void batchDeleteTeam(String corpid, List<Long> clueIdList, List<String> userIdList, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    /**
     * 批量剔除团队
     * @param corpid
     * @param clueIdList 线索id集合
     * @param userIdList
     */
    void batchDeleteByClueId(String corpid, List<Long> clueIdList, List<String> userIdList) throws XbbException;

    /**
     * 协同人批量升级
     * @param corpid
     * @param clueUserEntities
     */
    void batchUpgrade(String corpid, List<ClueUserEntity> clueUserEntities, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;


    /**
     * 更新del
     * @param corpid
     * @param clueUserEntities
     * @param refreshPolicy
     * @param del
     */
    void deleteBatch(String corpid, List<ClueUserEntity> clueUserEntities, WriteRequest.RefreshPolicy refreshPolicy, Integer del) throws XbbException;

    /**
     * @param corpid 公司id
     * @param clueId id
     * @param isMain 是否为负责人 1负责人 0 协同人
     * @return java.util.List<java.lang.String>
     */
    List<String> getClueUserIdList(String corpid, Long clueId, Integer isMain);
    /**
     * @param corpid 公司id
     * @param clueId id
     * @param isMain 是否为负责人 1负责人 0 协同人
     * @return java.util.List<java.lang.String>
     */
    List<ClueUserEntity> getClueUserList(String corpid, Long clueId, Integer isMain);

    List<String> getClueUserIds(String corpid, List<Long> clueIds, Integer isMain);


    /**
     * 公海规则查询负责人id
     * @param corpid
     * @param isMain
     * @param userId
     * @param startId data_id > startId
     * @param pageNum limit pageNum
     * @return
     */
    List<Long> getDataIdList4Rule(String corpid, Integer isMain, String userId, Long startId, Integer pageNum);

    /**
     * 更新协同人可编辑权限
     *
     * @param clueUserEntity
     */
    void updateEditFormPer(ClueUserEntity clueUserEntity) throws XbbException;

    /**
     * 编辑团队成员标签
     *
     * @param clueUserEntity
     */
    void editLabel(ClueUserEntity clueUserEntity) throws XbbException ;

    /**
     * 修改线索名称
     *
     * @param clueUserEntity
     */
    void renameTeam(ClueUserEntity clueUserEntity) throws XbbException;

    /**
     * 更新团队协同人信息和协同人可编辑权限
     *
     * @param corpid
     * @param idIn
     * @param updateUserToCoTeamList
     * @param coopUser
     * @param needThrow
     */
    void batchUpdateCoAndPerByUserIdIn(String corpid, List<Long> idIn, List<UserTeamEntity> updateUserToCoTeamList, Integer coopUser, boolean needThrow) throws XbbException;

    void batchUpdateCoAndPerByUserIdIn(String corpid, List<Long> idIn, List<UserTeamEntity> teamEntityList, Integer isMain, boolean needThrow, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    /**
     * 批量更新团队中的协同人的负责人信息
     *
     * @param corpid 公司id
     * @param idIn 团队表中的主键id
     * @param updateUserTeamMainList 更新协同人的负责人信息
     */
    void batchUpdateTeamMainByUserIdIn(String corpid, List<Long> idIn, List<UserTeamEntity> updateUserTeamMainList) throws XbbException;

    void batchUpdateTeamMainByUserIdIn(String corpid, List<Long> idIn, List<UserTeamEntity> updateUserTeamMainList, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;
}
